package com.wonderful.eyepetizer.ui.pages.person

import androidx.compose.runtime.mutableStateListOf
import androidx.lifecycle.viewModelScope
import com.wonderful.eyepetizer.app.base.BaseViewModel
import com.wonderful.eyepetizer.data.entity.bean.ItemData
import com.wonderful.eyepetizer.data.repo.MainRepo
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
 * Desc:
 * @Author: wonderful
 * @Time: 2024/2/26 11:39
 */
@HiltViewModel
class PersonViewModel @Inject constructor(private val mRepo: MainRepo) : BaseViewModel() {
    val videoList = mutableStateListOf<ItemData>()

    fun getVideoList() {
        viewModelScope.launch {
            val list = mRepo.getHistoryWatchList()
            if (list.isNotEmpty()) {
                videoList.clear()
                videoList.addAll(list)
            }
        }
    }

    fun deleteVideo(itemData: ItemData) {
        viewModelScope.launch {
            mRepo.deleteHistoryWatchItem(itemData)
            videoList.removeAll {
                it.id == itemData.id
            }
        }
    }
}